//
//  SMSInfoListCell.swift
//  MIFI
//
//  Created by 金嗓子卡卡 on 2019/5/13.
//  Copyright © 2019 NJMifi. All rights reserved.
//

import UIKit

class SMSInfoListCell: UITableViewCell {

    private lazy var phoneLabel: UILabel = {
        let label = UILabel(frame: CGRect(x: 30, y: 0, width: screenWidth - 150, height: 30))
        label.backgroundColor = clearColor
        label.textColor = blackColor
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: 20)
        return label
    }()
    
    private lazy var timeLabel: UILabel = {
        let label = UILabel(frame: CGRect(x: 0, y: 0, width: 80, height: 30))
        label.right = screenWidth - 20
        label.backgroundColor = clearColor
        label.textColor = textGray
        label.font = UIFont.systemFont(ofSize: 17)
        label.textAlignment = .right
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel(frame: CGRect(x: phoneLabel.left, y: phoneLabel.bottom, width: timeLabel.right - phoneLabel.left, height: 50))
        label.numberOfLines = 2
        label.font = UIFont.systemFont(ofSize: 17)
        label.textColor = timeLabel.textColor
        label.backgroundColor = clearColor
        return label
    }()
    
    private lazy var line: UIView = {
        let view = UIView(frame: CGRect(x: 32, y: 79.5, width: screenWidth - 22, height: 0.5))
        view.backgroundColor = textGray
        return view
    }()
    private lazy var bagImageView: UIImageView = {
        
        let  imageView = UIImageView()
        
        imageView.frame = CGRect.init(x:5, y: 35, width: 10, height: 10)
        imageView.backgroundColor = .red
        
        imageView.layer.cornerRadius = 5
        
        imageView.clipsToBounds = true
        
        imageView.isHidden = true
        return imageView
    }()
    
    
 
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        configView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configView() {
        selectionStyle = .default
        contentView.backgroundColor = clearColor
        contentView.addSubview(phoneLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(contentLabel)
        contentView.addSubview(line)
        contentView.addSubview(bagImageView)
    }
    
    func refresh(data:SMSListModel.Message) {
        phoneLabel.text = data.number
        let arr = data.date!.components(separatedBy: ",")
        timeLabel.text = arr[3] + ":" + arr[4]
        contentLabel.text = data.content?.unicodeStr
        if data.tag == "1" {
            
           bagImageView.isHidden = false
            
        }else{
            
             bagImageView.isHidden = true
        }
    }
    
}
